package com.xxxx.crm.controller;

import com.xxxx.crm.base.BaseController;
import com.xxxx.crm.base.ResultInfo;
import com.xxxx.crm.query.CusDevPlanQuery;
import com.xxxx.crm.service.CusDevPlanService;
import com.xxxx.crm.service.SaleChanceService;
import com.xxxx.crm.vo.CusDevPlan;
import com.xxxx.crm.vo.SaleChance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author:王亚栋
 * @Date:2022/12/25 17:00
 * @Version:1.0
 * 客户开发计划
 */
@Controller
@RequestMapping("cus_dev_plan")
public class CusDevPlanController extends BaseController {

    @Autowired
    private SaleChanceService saleChanceService;
    @Autowired
    private CusDevPlanService cusDevPlanService;

    /**
     * 进入客户开发主页
     * @return
     */
    @RequestMapping("/index")
    public String index(){

        return "cus_dev_plan/cus_dev_plan";
    }

    /**
     * 打开计划开发与详情页面
     * @param id
     * @return
     */
    @RequestMapping("/toCusDevPlanPage")
    public String toCusDevPlanPage(Integer id,
                                   HttpServletRequest request){

        //通过id查询营销机会对象
        SaleChance saleChance = saleChanceService.selectByPrimaryKey(id);
        //将对象设置到请求域中
        request.setAttribute("saleChance",saleChance);

        return "cus_dev_plan/cus_dev_plan_data";
    }

    /**
     * 多条件查询客户开发计划
     * @param cusDevPlanQuery
     * @return
     */
    @GetMapping("/queryCusDevPlanByParams")
    @ResponseBody
    public Map<String,Object> queryCusDevPlanByParams(CusDevPlanQuery cusDevPlanQuery){

        return cusDevPlanService.queryCusDevPlanByParams(cusDevPlanQuery);
    }

    /**
     * 添加计划项数据
     * @param cusDevPlan
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public ResultInfo addCusDevPlan(CusDevPlan cusDevPlan){

        cusDevPlanService.addCusDevPlan(cusDevPlan);

        return success("添加开发计划项数据成功！");
    }


    /**
     * 进入添加或修改计划项的页面
     * @return
     */
    @RequestMapping("/toAddOrUpdateCusDevPlanPage")
    public String toAddOrUpdateCusDevPlanPage(){

        return "cus_dev_plan/add_update";
    }

    /**
     * 更新计划项数据
     * @param cusDevPlan
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public ResultInfo updateCusDevPlan(CusDevPlan cusDevPlan){

        cusDevPlanService.updateCusDevPlan(cusDevPlan);

        return success("计划项更新成功！");
    }

    /**
     * 删除计划项
     * @param id
     * @return
     */
    public ResultInfo deleteCusDevPlan(Integer id){

        cusDevPlanService.deleteCusDevPlan(id);

        return success("计划项数据删除成功！");
    }



}
